-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[staking] Candidate Register without Staking #4059
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4059 +/- ##
==========================================
+ Coverage 75.38% 76.36% +0.98%
==========================================
Files 303 340 +37
Lines 25923 29022 +3099
==========================================
+ Hits 19541 22163 +2622
- Misses 5360 5754 +394
- Partials 1022 1105 +83 ☔ View full report in Codecov by Sentry. |
7ab6ddf
to
669b5ac
Compare
@@ -66,7 +70,11 @@ func (p *Protocol) validateCandidateRegister(ctx context.Context, act *action.Ca | |||
} | |||
|
|||
if act.Amount().Cmp(p.config.RegistrationConsts.MinSelfStake) < 0 { | |||
return errors.Wrap(action.ErrInvalidAmount, "self staking amount is not valid") | |||
featureCtx := protocol.MustGetFeatureCtx(ctx) | |||
if featureCtx.CandidateRegisterMustWithStake || act.Amount().Cmp(big.NewInt(0)) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if featureCtx.CandidateRegisterMustWithStake
always return error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, only featureCtx.CandidateRegisterMustWithStake==false && act.Amount()==0
is valid if act.Amount() < MinSelfStake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!featureCtx.CandidateRegisterMustWithStake && act.Amount()==0 is easier to read than featureCtx.CandidateRegisterMustWithStake || act.Amount().Cmp(big.NewInt(0)) != 0
action/protocol/staking/handlers.go
Outdated
// register with self-stake | ||
bucketIdx := uint64(candidateNoSelfStakeBucketIndex) | ||
var bucketLogs []*action.TransactionLog | ||
votes := big.NewInt(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use var ()
to put 3 together
@@ -529,7 +532,7 @@ func (cb *candBase) collision(d *Candidate) (address.Address, address.Address, a | |||
oper = c.Owner | |||
} | |||
|
|||
if c, hit := cb.selfStkBucketMap[d.SelfStakeBucketIdx]; hit && !address.Equal(c.Owner, d.Owner) { | |||
if c, hit := cb.selfStkBucketMap[d.SelfStakeBucketIdx]; hit && d.SelfStakeBucketIdx != candidateNoSelfStakeBucketIndex && !address.Equal(c.Owner, d.Owner) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change is this file should use what's in PR4061, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's part of PR4061
action/protocol/staking/handlers.go
Outdated
if err != nil { | ||
return log, nil, err | ||
} | ||
bucketIdx = bktIdx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L672: bucketIdx, err = csm.xxx
, no need to have a new var bktIdx
here
action/protocol/staking/handlers.go
Outdated
Amount: registrationFee, | ||
}, | ||
}, nil | ||
txLogs := append(bucketLogs, &action.TransactionLog{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to define a new txLogs
? can use existing bucketLogs
i think rename bucketLogs
to txLogs
to make the name more clear
action/protocol/staking/handlers.go
Outdated
Amount: act.Amount(), | ||
}) | ||
votes = p.calculateVoteWeight(bucket, true) | ||
log.AddTopics(byteutil.Uint64ToBytesBigEndian(bucketIdx), owner.Bytes()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be outside of if{}
-- registration without self-stake should also create a topic in the log
669b5ac
to
a6c1518
Compare
a6c1518
to
fca42c3
Compare
Quality Gate failedFailed conditions 4.6% Duplication on New Code (required ≤ 3%) |
return errors.Wrap(action.ErrInvalidAmount, "self staking amount is not valid") | ||
featureCtx := protocol.MustGetFeatureCtx(ctx) | ||
if featureCtx.CandidateRegisterMustWithStake || act.Amount().Cmp(big.NewInt(0)) != 0 { | ||
log.L().Warn("Candidate register amount is less than the minimum requirement", zap.Bool("feature", featureCtx.CandidateRegisterMustWithStake), zap.String("amount", act.Amount().String())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the error has been logged upstream
action/protocol/staking/handlers.go
Outdated
votes = big.NewInt(0) | ||
err error | ||
) | ||
if act.Amount().Sign() > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no hardfork here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the hard fork, the act.Amount
must be greater than 0 (garunteed by action validation), behaves the same as in the old version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if act.Amount().Sign() <= 0 {
should be return error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
action/protocol/staking/handlers.go
Outdated
bucketIdx, err := csm.putBucketAndIndex(bucket) | ||
if err != nil { | ||
return log, nil, err | ||
// register with self-stake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to L713
Recipient: address.StakingBucketPoolAddr, | ||
Amount: act.Amount(), | ||
}) | ||
votes = p.calculateVoteWeight(bucket, true) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think adding an else make the code more explicit
else {
// register w/o self-stake, waiting to be endorsed
bucketIdx = uint64(candidateNoSelfStakeBucketIndex)
votes = big.NewInt(0)
}
action/protocol/staking/handlers.go
Outdated
bucketIdx = uint64(candidateNoSelfStakeBucketIndex) | ||
txLogs []*action.TransactionLog | ||
votes = big.NewInt(0) | ||
err error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- withSelfStake = act.Amount().Sign() > 0
err error
not ncessary?
action/protocol/staking/handlers.go
Outdated
votes = big.NewInt(0) | ||
err error | ||
) | ||
if act.Amount().Sign() > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if withSelfStake {
action/protocol/staking/handlers.go
Outdated
return log, nil, &handleError{ | ||
err: errors.Wrapf(err, "failed to update staking bucket pool %s", err.Error()), | ||
failureStatus: iotextypes.ReceiptStatus_ErrWriteAccount, | ||
if act.Amount().Sign() > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if withSelfStake {
Quality Gate failedFailed conditions |
Description
We expanded the action
CandidateRegister
to support registration without staking. However, in the absence of self-staking, they will not be selected as consensus nodes.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: